package com.zhou.springcloud.api.serivce;

import com.zhou.springcloud.api.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhouyongjun
 * @Description:
 * @date 2021/3/25 8:50
 */
//hystrix降级
@Component
public class DeptClientFallBackFactory implements FallbackFactory {
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public Dept queryById(Long id) {
                return new Dept()
                        .setDeptno(id)
                        .setDname("id=>"+id+"没有对应的信息，客户端提供了降级的信息，这个服务现在已经被关闭")
                        .setDbSource("没有数据");
            }

            @Override
            public List<Dept> queryAll() {
                return new ArrayList<>();
            }

            @Override
            public Boolean addDept(Dept dept) {
                return false;
            }
        };
    }
}
